<%@ page language="java" import="java.util.List" pageEncoding="UTF-8"%>
<%@ page import= "com.roadmap.common.BaseConst"%>
<%@ page import="com.roadmap.struts.action.ActionConst"%>
<%@ page import="com.roadmap.common.RdcResourceBundle" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String user_ssn_id = (String)request.getSession().getAttribute(ActionConst.Aspirant_Id_In_Session);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="expires" content="0"/> 
<link href="res/css/layout.css" rel="stylesheet" type="text/css" media="all" />
<link href="res/css/sns.css" rel="stylesheet" type="text/css" media="all" />
<link href="res/css/widget.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="dwr/util.js"></script>
<script type="text/javascript" src="dwr/engine.js"></script>
<script type="text/javascript" src="dwr/interface/RdcAjax.js"></script>
<script type="text/javascript" src="res/js/func.js"></script>
<script type="text/javascript" src="res/js/component.js"></script>
<script type="text/javascript" src="res/js/widget.js"></script>
<title>请求中心 | <%=RdcResourceBundle.COMPANY_NAME %></title>

</head>

<body>
	<jsp:include page="/admin/myheader.jsp"></jsp:include>
	
	<!-- define the frame for logging on-->
	<div class="mainbody"><div class="manager">
	<jsp:include page="/admin/sns/nav_btns.jsp"/>
	
	<!-- middle part: content -->
	<div class="middle-part">
		<div class="section">
			<div class="title-sp">请求中心</div>
		</div>
		<div class="section">
			<div class="requestlist">
				<logic:notPresent name="requests"><span class="prompt-message">您没有好友请求</span></logic:notPresent>
				
				<logic:present name="requests">
				<div class="spec"><strong id="requestCount"><%=((List)request.getAttribute("requests")).size() %></strong>个好友请求</div>
				<ul>
					<logic:iterate id="req" name="requests">
					<bean:define id="dispId" name="req" property="id"/>
					<li id="req<%=dispId %>">
						<div class="smallpicture"><img src="<%=BaseConst.PURIKURA_DIR_SMALL%><%=dispId %>.gif" alt="<%=RdcResourceBundle.COMPANY_NAME %>"/></div>
						<div class="request">
							<ul> 
								<li>
									<span class="float-left"><a href="aspirant.do?uid=<%=dispId %>"><span id="name<%=dispId %>"><bean:write name="req" property="requester"/></span></a>请求成为您的好友</span>
									<span class="float-right"><a href="javascript:completeRequest('<%=dispId %>');">同意</a>&nbsp;&nbsp;&nbsp;<a href="javascript:skipRequest('<%=dispId %>');">忽略</a></span>
								</li>
								<li>附言：<span id="note<%=dispId %>"><bean:write name="req" property="note"/></span></li>
							</ul>
						</div>
					</li>
					</logic:iterate>
				</ul>
				</logic:present>
			</div>
		</div>
		
	</div>
	
	<!-- right part: -->
	<div class="right-part">
	</div>
	
	</div>
	
	<div class="clear-div"></div>
	</div>
	
	<jsp:include page="/res/jsp/footer.jsp"></jsp:include>

<script type="text/javascript">
	
	window.onload = function(){
		// PromptDialog.resize(250, 50);
	}
	
	// the declarification of the object should be behind the its overided methods
	var requestPopup = new ConfirmRequestPopup();
	function completeRequest(disptId){
		if(!RDC.util.isString(disptId) && disptId != ""){
			alert("不合法的参数");
			return;
		}
		
		if(!RDC.util.verifyText($("note" + disptId).innerHTML, 0, 50)) {
			PromptDialog.show("附言字符不超过50个字");
			return;
		}
		
		name = $("name" + disptId).innerHTML;
		requestPopup.setData(disptId, '<%=user_ssn_id%>', name);
		requestPopup.show();
	}
	
	var deltedReqId = null;
	var popupWin = new PopUpWindow("忽略该好友请求？", "您如果忽略该请求，系统不会告诉TA", 0);
	popupWin.addAction(skipAction(popupWin));
	popupWin.addAction(closeAction(popupWin));
	
	function skipRequest(dispId){
		if(!RDC.util.isString(dispId) && dispId != ""){
			alert("不合法的参数");
			return;
		}
		
		deltedReqId = dispId;
		popupWin.show();
	}
	
	function skipAction(dlg){
		var btn = dlg.createAction("确定");
		btn.id = "confirm_cancel";
		btn.onclick = function(){
			RdcAjax.skipRequest(deltedReqId, function(data){
				if(typeof data.id !== 'undefined'){
					rli = $("req" + data.id);
					if(rli != null){
						RDC.gui.removeNode(rli);
						if(RDC.util.isNumber($("requestCount").innerHTML)){
							$("requestCount").innerHTML = parseInt($("requestCount").innerHTML) - 1;
						}
					}
					else {
						alert("invalid parameter");
					}
					
					PromptDialog.show("处理成功");
				}
				else {
					PromptDialog.show("处理失败，因为" + data);
				}
				
				popupWin.hide(0);
			});
		}
		return btn;
	}
	
	function closeAction(dlg){
		var btn = document.createElement("input");		
		btn.type = "button";
		btn.className = "cancelBtn";
		btn.value = "返回";
		btn.onclick = function(){
			dlg.hide(0);
		};		
		return btn;
	}


</script>

</body>

</html>
